package com.hspedu.newData.dmsxl.贪心算法.mid.序列问题;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-20 
 * @Version: 1.0
 */

public class LC376摆动序列 {

    public int wiggleMaxLength(int[] nums) {

        if (nums.length <= 1){
            return nums.length;
        }

        // 当前差值
        int curDiff = 0;

        // 上一个差值
        int preDiff = 0;

        int count = 1;

        for (int i = 1; i < nums.length; i++) {
            curDiff = nums[i] - nums[i-1];

            if ((curDiff > 0 && preDiff <= 0)||(curDiff<0&&preDiff>=0)){
                preDiff = curDiff;
                count++;
            }

        }

        return count;
    }

}
